package com.slin.config;

import cn.hutool.core.date.DateUtil;
import com.google.common.collect.Lists;
import io.swagger.annotations.ApiOperation;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ParameterBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.schema.ModelRef;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.service.Parameter;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Configuration
@EnableSwagger2
public class SwaggerConfig {
	
    @Bean
    public Docket api()
		{
			List<Parameter> aParameters = new ArrayList<Parameter>();
			return new Docket(DocumentationType.SWAGGER_2).apiInfo(getApiInfo()).useDefaultResponseMessages(false).globalOperationParameters(aParameters)
					.select().apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class)).paths(PathSelectors.any()).build();
    }
    
	protected ApiInfo getApiInfo() {
		String msg = "基本的返回结果是一个json,json至少包含两个字段code,msg, code=200 代表成功,msg会携带消息, 如果 code不等200,则说明本次调用失败,需要展示消息内容\n 需要用户登陆才能调用的API,需要传入token字段";
		return new ApiInfo("ZNTRADE B2C", "ZNTRADE B2C AdminAPI 发布时间:&nbsp;" + DateUtil.formatDateTime(new Date()) +"\n"+msg, "1.0",
				"1.1", new Contact("ZNTRADE开发团队", "", ""), "", "", Lists.newArrayList());
	}
}